package com.controller;

import com.github.pagehelper.PageInfo;
import com.model.*;
import com.query.PlatformFlowQuery;
import com.service.config.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author
 * @Description: 配置管理
 * @date 2021/4/18 11:02
 */
@RestController
@RequestMapping("/config")
@Api(tags = "配置管理模块", value = "配置管理模块相关api")
public class ConfigController {

    @Autowired
    private ConfigService configService;

    @GetMapping("/application/list")
    @ApiOperation(value = "应用配置管理-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "应用ID", required = false),
            @ApiImplicitParam(name = "pageNo", value = "分页条码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true)
    })
    public ReponseDto<PageInfo<HomeAppConfigModel>> applicationList(@RequestParam(value = "id",required = false) Long id,
                                                                    @RequestParam(value = "pageNo",required = true) String pageNo,
                                                                    @RequestParam(value = "pageSize",required = true) Integer pageSize){
        return new ReponseDto<>(configService.applicationList(id,pageNo,pageSize));
    }

    @GetMapping("/application/detail/{id}")
    @ApiOperation(value = "应用配置管理-详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "应用ID", required = false)
    })
    public ReponseDto<HomeAppConfigModel> applicationDetail(@PathVariable(value = "id",required = true) Long id){
        return new ReponseDto<>(configService.applicationDetail(id));
    }

    @PostMapping("/application/add")
    @ApiOperation(value = "应用配置管理-新增")
    public ReponseDto applicationAdd(@RequestBody HomeAppConfig config,
                                     @RequestHeader String userId,
                                     @RequestHeader String username){
        configService.applicationAdd(config,userId,username);
        return new ReponseDto<>();
    }

    @PostMapping("/application/update")
    @ApiOperation(value = "应用配置管理-修改")
    public ReponseDto applicationUpdate(@RequestBody HomeAppConfig config,
                                        @RequestHeader String userId,
                                        @RequestHeader String username){
        configService.applicationUpdate(config, userId, username);
        return new ReponseDto<>();
    }

    @GetMapping("/application/delete/{id}")
    @ApiOperation(value = "应用配置管理-删除")
    public ReponseDto applicationDelete(@PathVariable("id") Long id,
                                        @RequestHeader String userId,
                                        @RequestHeader String username){
        configService.applicationDelete(id, userId, username);
        return new ReponseDto<>();
    }


    @GetMapping("/advisory/{type}/list")
    @ApiOperation(value = "咨询管理、公告配置-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "菜单类型 0资讯管理 1公告配置", paramType = "path", required = true),
            @ApiImplicitParam(name = "id", value = "ID", required = false),
            @ApiImplicitParam(name = "pageNo", value = "分页条码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true)
    })
    public ReponseDto<PageInfo<ArticleInfoConfigModel>> advisoryList(@PathVariable(value = "type",required = false) Integer type,
                                                                     @RequestParam(value = "id",required = false) Long id,
                                                                     @RequestParam(value = "pageNo",required = true) String pageNo,
                                                                     @RequestParam(value = "pageSize",required = true) Integer pageSize){
        return new ReponseDto<>(configService.advisoryList(type,id,pageNo,pageSize));
    }

    @PostMapping("/advisory/{type}/add")
    @ApiOperation(value = "咨询管理、公告配置-新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "菜单类型 0资讯管理 1公告配置", paramType = "path", required = true),
            @ApiImplicitParam(name = "config", value = "资讯、公告", required = true)
    })
    public ReponseDto advisoryAdd(@PathVariable(name = "type",required = true) Integer type,
                                  @Valid @RequestBody ArticleInfoConfig config,
                                  @RequestHeader String userId,
                                  @RequestHeader String username){
        configService.advisoryAdd(type,config,userId,username);
        return new ReponseDto<>();
    }

    @PostMapping("/advisory/detail/{id}")
    @ApiOperation(value = "咨询管理、公告配置-详情")
    public ReponseDto<ArticleInfoConfigModel> advisoryDetail(@PathVariable("id") Long id){
        return new ReponseDto<>(configService.advisoryDetail(id));
    }

    @PostMapping("/advisory/update")
    @ApiOperation(value = "咨询管理、公告配置-修改")
    public ReponseDto advisoryUpdate(@RequestBody ArticleInfoConfig config,
                                        @RequestHeader String userId,
                                        @RequestHeader String username){
        configService.advisoryUpdate(config, userId, username);
        return new ReponseDto<>();
    }

    @GetMapping("/advisory/delete/{id}")
    @ApiOperation(value = "咨询管理、公告配置-删除")
    public ReponseDto advisoryDelete(@PathVariable("id") Long id,
                                        @RequestHeader String userId,
                                        @RequestHeader String username){
        configService.advisoryDelete(id, userId, username);
        return new ReponseDto<>();
    }


    @GetMapping("/carousel/list")
    @ApiOperation(value = "轮播图管理-列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = false),
            @ApiImplicitParam(name = "pageNo", value = "分页条码", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true)
    })
    public ReponseDto<PageInfo<CarouselModel>> carouselList(@RequestParam(value = "id",required = false) Long id,
                                                                     @RequestParam(value = "pageNo",required = true) String pageNo,
                                                                     @RequestParam(value = "pageSize",required = true) Integer pageSize){
        return new ReponseDto<>(configService.carouselList(id,pageNo,pageSize));
    }

    @GetMapping("/carousel/detail/{id}")
    @ApiOperation(value = "轮播图管理-详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = false,paramType = "path")
    })
    public ReponseDto<CarouselModel> carouselDetail(@PathVariable(value = "id",required = false) Long id){
        return new ReponseDto<>(configService.carouselDetail(id));
    }

    @PostMapping("/carousel/add")
    @ApiOperation(value = "轮播图管理-新增")
    public ReponseDto carouselAdd(@Valid @RequestBody Carousel carousel,
                                  @RequestHeader String userId,
                                  @RequestHeader String username){
        configService.carouselAdd(carousel,userId,username);
        return new ReponseDto<>();
    }

    @PostMapping("/carousel/update")
    @ApiOperation(value = "轮播图管理-修改")
    public ReponseDto carouselUpdate(@Valid @RequestBody Carousel carousel,
                                     @RequestHeader String userId,
                                     @RequestHeader String username){
        configService.carouselUpdate(carousel, userId, username);
        return new ReponseDto<>();
    }

    @GetMapping("/carousel/delete/{id}")
    @ApiOperation(value = "轮播图管理-删除")
    public ReponseDto carouselDelete(@PathVariable("id") Long id,
                                     @RequestHeader String userId,
                                     @RequestHeader String username){
        configService.carouselDelete(id, userId, username);
        return new ReponseDto<>();
    }

}
